﻿@using eLoan.Models;
@model CollectionReconciliationReportModel

@{
    ViewBag.Title = "Daily Collection Reconciliation Report";
}

<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-10">
        <h2>Daily Collection Reconciliation Report</h2>
        <ol class="breadcrumb">
            <li>
                Reports
            </li>
            <li class="active">
                <strong>Daily Collection Reconciliation Report</strong>
            </li>
        </ol>
    </div>
    <div class="col-lg-2"></div>
</div>


<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
            @using (Html.BeginForm("RefreshCollectionReconciliationReport", "Report", FormMethod.Post, new { id = "saveForm" }))
            {
                <fieldset>
                    <div class="ibox-title">
                        <div class="divSearch">
                            <table class="table-search">
                                <tr>
                                    <td class="tdFixed">
                                        <span>@Html.LabelFor(m => m.Branches)</span>
                                        @Html.DropDownListFor(m => m.SelectedBranchCode, Model.Branches, new { @id = "ddlBranches", @onchange = "GetAgents()", @class = "text-box single-line", @width = "50%" })
                                    </td>
                                    <td class="tdFixed">
                                        <span>@Html.LabelFor(m => m.Agents)</span>
                                        @Html.DropDownListFor(m => m.SelectedAgentID, Model.Agents, new { @id = "ddlAgents", @class = "text-box single-line", @width = "50%" })
                                    </td>
                                    <td class="tdFixed">
                                        <span>@Html.LabelFor(m => m.CollectionDate)</span>
                                        <div class="form-group" id="cd">
                                            <div class="input-group date">
                                                <span class="input-group-addon">
                                                    <i class="fa fa-calendar"></i>
                                                </span>
                                                @Html.TextBoxFor(m => m.CollectionDate, "{0:MM/dd/yyyy}", new { @id = "txtCollectionDate", @class = "form-control" })
                                            </div>
                                        </div>
                                    </td>
                                    <td class="tdFixed">
                                        <button type="submit" id="btnSearch" class="btn btn-primary btnSearch" name="command" value="Refresh">Search</button>
                                    </td>
                                    <td class="tdAlignRight">
                                        <button type="submit" id="btnExport" class="btn btn-primary btnSearch" name="command" value="Export">Export to pdf</button>
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </div>
                    <div class="ibox-title">
                        <h3>SUMMARY</h3>
                    </div>
                    <div class="ibox-content">
                        <table class="table table-bordered">
                            <thead>
                                <tr>
                                    <th style="width:33.33%">Total Collection Per Record</th>
                                    <th style="width:33.33%">Total Actual Cash Collection</th>
                                    <th style="width:33.33%">Total Short / Over</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr>
                                    <td>
                                        @Html.ValueFor(m => m.TotalCollectionPerRecord, "{0:#,###,##0.00}")
                                        @Html.HiddenFor(m => m.TotalCollectionPerRecord)
                                    </td>
                                    <td>
                                        @Html.ValueFor(m => m.TotalActualCashCollection, "{0:#,###,##0.00}")
                                        @Html.HiddenFor(m => m.TotalActualCashCollection)
                                    </td>
                                    <td>
                                        @Html.ValueFor(m => m.TotalShortOver, "{0:#,###,##0.00}")
                                        @Html.HiddenFor(m => m.TotalShortOver)
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                        <table class="table table-bordered">
                            <thead>
                                <tr>
                                    <th style="width:16.67%">Total Cash Deposited</th>
                                    <th style="width:16.67%">Total Deducted To Cheque - Advance Payment</th>
                                    <th style="width:16.67%">Total Deducted To Cheque - Savings</th>
                                    <th style="width:16.67%">Total Used for Loan Release</th>
                                    <th style="width:16.67%">Total Used in Withdrawal of Savings</th>
                                    <th style="width:16.67%">Total Others</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr>
                                    <td>
                                        @Html.ValueFor(m => m.TotalCashDeposited, "{0:#,###,##0.00}")
                                        @Html.HiddenFor(m => m.TotalCashDeposited)
                                    </td>
                                    <td>
                                        @Html.ValueFor(m => m.TotalDeductedToChequeAdvancePayment, "{0:#,###,##0.00}")
                                        @Html.HiddenFor(m => m.TotalDeductedToChequeAdvancePayment)
                                    </td>
                                    <td>
                                        @Html.ValueFor(m => m.TotalDeductedToChequeSavings, "{0:#,###,##0.00}")
                                        @Html.HiddenFor(m => m.TotalDeductedToChequeSavings)
                                    </td>
                                    <td>
                                        @Html.ValueFor(m => m.TotalUsedForLoanRelease, "{0:#,###,##0.00}")
                                        @Html.HiddenFor(m => m.TotalUsedForLoanRelease)
                                    </td>
                                    <td>
                                        @Html.ValueFor(m => m.TotalUsedInWithdrawalOfSavings, "{0:#,###,##0.00}")
                                        @Html.HiddenFor(m => m.TotalUsedInWithdrawalOfSavings)
                                    </td>
                                    <td>
                                        @Html.ValueFor(m => m.TotalOthers, "{0:#,###,##0.00}")
                                        @Html.HiddenFor(m => m.TotalOthers)
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                    <div class="ibox-title">
                        <h3>Collection per Record</h3>
                    </div>
                    <div class="ibox-title">
                        <table class="table table-bordered table-List">
                            <thead>
                                <tr>
                                    <th>Agent</th>
                                    <th style="width: 200px;">Posted Payment</th>
                                    <th style="width: 200px;">Penalty</th>
                                </tr>
                            </thead>
                            <tbody>
                                @for (var i = 0; i < Model.CollectionOnRecordItems.Count(); i++)
                                {
                                    <tr>
                                        <td>
                                            @Html.DisplayFor(m => m.CollectionOnRecordItems[i].AgentName)
                                            @Html.HiddenFor(m => m.CollectionOnRecordItems[i].AgentName)
                                            @Html.HiddenFor(m => m.CollectionOnRecordItems[i].AgentID)
                                        </td>
                                        <td style="text-align:right;">
                                            @Html.ValueFor(m => m.CollectionOnRecordItems[i].PostedPayment, "{0:#,###,##0.00}")
                                            @Html.HiddenFor(m => m.CollectionOnRecordItems[i].PostedPayment)
                                        </td>
                                        <td style="text-align:right;">
                                            @Html.ValueFor(m => m.CollectionOnRecordItems[i].Penalty, "{0:#,###,##0.00}")
                                            @Html.HiddenFor(m => m.CollectionOnRecordItems[i].Penalty)
                                        </td>
                                    </tr>
                                }
                            </tbody>
                        </table>
                    </div>
                    <div class="ibox-title">
                        <h3>Actual Cash Collection</h3>
                    </div>
                    <div class="ibox-content">
                        <table id="tbl" class="table table-bordered table-List">
                            <thead>
                                <tr>
                                    <th>Agent</th>
                                    <th style="width:80px">Total Collection Per Record</th>
                                    <th style="width:80px">Cash Deposited</th>
                                    <th style="width:80px">Deducted To Cheque - Advance Payment</th>
                                    <th style="width:80px">Deducted To Cheque - Savings</th>
                                    <th style="width:80px">Used For Loan Release</th>
                                    <th style="width:80px">Used In Withdrawal Of Savings</th>
                                    <th style="width:80px">Others</th>
                                    <th>Remarks</th>
                                    <th style="width:80px">Total</th>
                                    <th style="width:80px">Difference</th>
                                    <th>Status</th>
                                    <th></th>
                                </tr>
                            </thead>
                            <tbody id="tableBody">
                                @for (var i = 0; i < Model.CollectionReconciliationItems.Count(); i++)
                                {
                                    <tr>
                                        <td>
                                            @Html.DisplayFor(m => m.CollectionReconciliationItems[i].AgentName)
                                            @Html.HiddenFor(m => m.CollectionReconciliationItems[i].AgentName)
                                            @Html.HiddenFor(m => m.CollectionReconciliationItems[i].AgentID)
                                        </td>
                                        <td style="text-align:right;">
                                            @Html.ValueFor(m => m.CollectionReconciliationItems[i].TotalCollectionPerRecord, "{0:#,###,##0.00}")
                                            @Html.HiddenFor(m => m.CollectionReconciliationItems[i].TotalCollectionPerRecord)
                                        </td>
                                        <td style="text-align:right;">
                                            @Html.ValueFor(m => m.CollectionReconciliationItems[i].CashDeposited, "{0:#,###,##0.00}")
                                            @Html.HiddenFor(m => m.CollectionReconciliationItems[i].CashDeposited)
                                        </td>
                                        <td style="text-align:right;">
                                            @Html.ValueFor(m => m.CollectionReconciliationItems[i].DeductedToChequeAdvancePayment, "{0:#,###,##0.00}")
                                            @Html.HiddenFor(m => m.CollectionReconciliationItems[i].DeductedToChequeAdvancePayment)
                                        </td>
                                        <td style="text-align:right;">
                                            @Html.ValueFor(m => m.CollectionReconciliationItems[i].DeductedToChequeSavings, "{0:#,###,##0.00}")
                                            @Html.HiddenFor(m => m.CollectionReconciliationItems[i].DeductedToChequeSavings)
                                        </td>
                                        <td style="text-align:right;">
                                            @Html.ValueFor(m => m.CollectionReconciliationItems[i].UsedForLoanRelease, "{0:#,###,##0.00}")
                                            @Html.HiddenFor(m => m.CollectionReconciliationItems[i].UsedForLoanRelease)
                                        </td>
                                        <td style="text-align:right;">
                                            @Html.ValueFor(m => m.CollectionReconciliationItems[i].UsedInWithdrawalOfSavings, "{0:#,###,##0.00}")
                                            @Html.HiddenFor(m => m.CollectionReconciliationItems[i].UsedInWithdrawalOfSavings)
                                        </td>
                                        <td style="text-align:right;">
                                            @Html.ValueFor(m => m.CollectionReconciliationItems[i].Others, "{0:#,###,##0.00}")
                                            @Html.HiddenFor(m => m.CollectionReconciliationItems[i].Others)
                                        </td>
                                        <td>
                                            @Html.DisplayFor(m => m.CollectionReconciliationItems[i].Remarks)
                                            @Html.HiddenFor(m => m.CollectionReconciliationItems[i].Remarks)
                                        </td>
                                        <td  style="text-align:right;">
                                            @Html.ValueFor(m => m.CollectionReconciliationItems[i].Total, "{0:#,###,##0.00}")
                                            @Html.HiddenFor(m => m.CollectionReconciliationItems[i].Total)
                                        </td>
                                        <td style="text-align:right;">
                                            @Html.ValueFor(m => m.CollectionReconciliationItems[i].Difference, "{0:#,###,##0.00}")
                                            @Html.HiddenFor(m => m.CollectionReconciliationItems[i].Difference)
                                        </td>
                                        <td>
                                            @Html.DisplayFor(m => m.CollectionReconciliationItems[i].Status)
                                            @Html.HiddenFor(m => m.CollectionReconciliationItems[i].StatusID)
                                            @Html.HiddenFor(m => m.CollectionReconciliationItems[i].Status)
                                        </td>
                                        <td>@Html.ActionLink("Review", "CollectionReconciliationReportEdit", "Report", null, null, null, new { id = Model.CollectionReconciliationItems[i].ID }, null)</td>
                                    </tr>
                                }
                            </tbody>

                        </table>

                        <button type="submit" id="btnRefresh" class="hidden" name="command" value="Refresh">Refresh</button>

                    </div>



                </fieldset>
            }
            </div>

        </div>
    </div>
</div>

@section Styles {
    @Styles.Render("~/Content/plugins/dataTables/dataTablesStyles")
    @Styles.Render("~/plugins/dataPickerStyles")
    
<style>
    .divScroll {
        height: 400px;
        overflow-x: scroll;
        border: solid 1px #EBEBEB;
    }

    .divSearch {
        background-color: #F5F5F6;
        border: 1px solid #EBEBEB;
        margin-top: 5px;
    }

    .table-search {
        width: 100%;
        border: none;
    }

        .table-search td {
            margin: 10px 10px 10px 10px;
            padding: 10px 10px 10px 10px;
            vertical-align: bottom;
        }

        .table-search .tdAlignRight {
            text-align: right;
        }

        .table-search .tdFixed {
            width: 20%;
        }

            .table-search .tdFixed div {
                margin-bottom: 0px;
            }

        .table-search td .btnSearch {
            margin-bottom: 0px;
        }


        .table-search td span {
            margin-left: 7px;
        }
</style>
    
}

@section Scripts {
@Scripts.Render("~/plugins/dataTables")
@Scripts.Render("~/plugins/dataPicker")
<script type="text/javascript">

    $(document).ready(function () {

        SetDateFormat();

        $('.table-List').dataTable({
            ordering: true,
            searching: false,
            paging: false
        });

        $(window).keydown(function (event) {
            if (event.keyCode == 13) {
                Refresh();
                return false;
            }
        });

    });

    function SetDateFormat() {

        $('#cd .input-group.date').datepicker({
            todayBtn: "linked",
            keyboardNavigation: false,
            forceParse: false,
            calendarWeeks: true,
            format: 'mm/dd/yyyy',
            autoclose: true

        });

        var cd = $('#txtCollectionDate').val();
        $('#cd .input-group.date').datepicker("update", new Date(cd));

    }

    function GetAgents()
    {
        var val = $('#ddlBranches').val();
        var subItems = "";
        
        $.getJSON("@Url.Action("GetAgents","Loan")", { branchCode: val },
    function (data) {
        subItems += "<option value='0'>All</option>"
        $.each(data, function (index, item) {

            subItems += "<option value='" + $.trim(item.Value) + "'>" + $.trim(item.Text) + "</option>"

        });
                
        $("#ddlAgents").html(subItems)
    });
 
    }

    function Refresh() {
        document.getElementById('btnRefresh').click();
    }

</script>

}
